package top.xana.acg.anime.binding

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.flow.Flow
import top.xana.acg.anime.utils.LogE

object RecyclerViewBinding {

    @JvmStatic
    @BindingAdapter("adapter")
    fun bindAdapter(view: RecyclerView, adapter: RecyclerView.Adapter<*>) {
        view.adapter = adapter
    }

    @JvmStatic
    @BindingAdapter("submitList")
    fun bindSubmitList(view: RecyclerView, itemList: List<Any>?) {
        val adapter = (view.adapter as? com.drake.brv.BindingAdapter) ?: kotlin.run {
            LogE("The adapter of RecyclerView isn`t ListAdapter")
            return
        }
        adapter.models = itemList
    }

    @JvmStatic
    @BindingAdapter("itemDecorations")
    fun bindItemDecorations(
        view: RecyclerView,
        itemDecoration: RecyclerView.ItemDecoration
    ) {
        view.addItemDecoration(itemDecoration)
    }

}
